NoteBook Personnalité Agréagle

Initialisation de Cherry


In [ ]:
import time
from poppy.creatures import PoppyHumanoid
from cherry import Cherry

from pypot.primitive.move import MoveRecorder, Move, MovePlayer

cherry = Cherry()
cherry.setup()

for m in cherry.robot.motors :
    m.goal_position = 0.0
    
for m in cherry.robot.head :
    m.compliant = False
for m in cherry.robot.arms :
    m.compliant = True

cherry.robot.head_z.goal_position = 0.0
cherry.robot.head_y.goal_position = 0.0

Initialisation thread audio


In [ ]:
import time
import sys
from threading import Thread, RLock
import mp3play
        
class MP3Read(Thread):

    """Thread chargé"""

    def __init__(self, fname):
        Thread.__init__(self)
        self.filename = fname

    def run(self):
        mp3 = mp3play.load(self.filename)
        mp3.play()
        time.sleep(min(35, mp3.seconds()))
        mp3.stop()

Initialisation thread controle des mouvements


In [ ]:
#CHERRY AGREABLE

import pygame
import time
import random
import sys
from threading import Thread, RLock

def get():
    out = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    it = 0 #iterator
    pygame.event.pump()
    
    #Read input from the two joysticks       
    for i in range(0, j.get_numaxes()):
        out[it] = j.get_axis(i)
        it+=1

    for i in range(0,j.get_numhats()):
        out[it] = j.get_hat(i)
        it+=1

    #Read input from buttons
    for i in range(0, j.get_numbuttons()):
        out[it] = j.get_button(i)
        it+=1
    return out

verrou = RLock()
        
class GamePadRead(Thread):

    """Thread chargé simplement d'afficher un mot dans la console."""

    def __init__(self, mot):
        Thread.__init__(self)
        self.mot = mot
        self.running = False
        self.zHead = cherry.robot.head_z.present_position
        self.yHead = cherry.robot.head_y.present_position

    def run(self):
        """Code à exécuter pendant l'exécution du thread."""
        self.running = True
        while self.running:
            with verrou:
                tab = get()
                
                #Mouvement de tête avec le Hat
                temp = tab[4][0]*2
                if(-90<self.zHead+temp <90):
                    self.zHead += tab[4][0]*2
                
                temp = tab[4][1]*(-2)
                if(self.yHead+temp < 20):
                    self.yHead += temp
                
                cherry.robot.head_z.goal_position = self.zHead
                cherry.robot.head_y.goal_position = self.yHead
                
                
                #Mouvement
                if tab[5] == 1 :
                    cherry.robot.rest_position.start()
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase1.mp3')
                    threadMp3.start()
                    time.sleep(1)
                    cherry.robot.rest_tilted_behave.start()
                    time.sleep(3)
                    cherry.robot.question_behave.start()
                    time.sleep(1.5)
                    cherry.robot.rest_position.start()
                
                if tab[6] == 1 :#tab[2] < -0.9 :
                    cherry.robot.left_arm_up_behave.start()
                    time.sleep(0.6)
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase2.mp3')
                    threadMp3.start()

                    time.sleep(1)
                    cherry.robot.rest_position.start()
                    
                if tab[7] == 1 :
                    cherry.robot.rest_tilted_behave.start()
                    time.sleep(0.5)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase3.mp3')
                    threadMp3.start()

                    time.sleep(2.5)
                    cherry.robot.question_behave.start()

                    time.sleep(1.5)
                    cherry.robot.rest_position.start()
                 
                if tab[8] == 1 and tab[2] < -0.9 :
                    cherry.robot.left_arm_up_behave.start()
                    time.sleep(0.3)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase4oui.mp3')
                    threadMp3.start()

                    time.sleep(0.5)
                    cherry.robot.rest_position.start()
                
                elif tab[8] == 1 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase4.mp3')
                    threadMp3.start()
                    time.sleep(2.4)
                    cherry.robot.you_and_me_behave.start()

                    time.sleep(2)
                    cherry.robot.rest_position.start()
                    
                if tab[9] == 1 and tab[2] < -0.9 :
                    cherry.robot.little_laugh_behave.start()
                    time.sleep(1)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase5.mp3')
                    threadMp3.start()

                    time.sleep(2)
                    cherry.robot.left_arm_up_behave.start()

                    time.sleep(2)

                    cherry.robot.rest_position.start()
                
                elif tab[9] == 1 :
                    cherry.robot.sigh_behave.start()
                    time.sleep(0.8)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase5non.mp3')
                    threadMp3.start()

                    time.sleep(2)
                    cherry.robot.little_hug_behave.start()

                    time.sleep(2)

                    cherry.robot.rest_position.start()
                    
                if tab[10] == 1 and tab[2] < -0.9 :
                    cherry.robot.left_arm_up_behave.start()

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase6Yes.mp3')
                    threadMp3.start()

                    time.sleep(1.5)

                    cherry.robot.rest_position.start()
                elif tab[10] == 1 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase6.mp3')
                    threadMp3.start()

                    time.sleep(1.5)
                    cherry.robot.left_arms_behave.start()

                    time.sleep(1.5)

                    cherry.robot.rest_position.start()
                
                if tab[11] == 1 :
                    cherry.robot.question_behave.start()

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase7.mp3')
                    threadMp3.start()

                    time.sleep(1.5)

                    cherry.robot.rest_position.start()
                
                if tab[12] == 1 :
                    cherry.robot.me_behave.start()
                    time.sleep(0.3)
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase8.mp3')
                    threadMp3.start()
                    time.sleep(1)
                    cherry.robot.rest_position.start()
                
                if tab[13] == 1 :
                    threadMp3 = MP3Read('../utils/audio/oui.mp3')
                    threadMp3.start()
                    time.sleep(0.5)
                
                if tab[14] == 1 :
                    threadMp3 = MP3Read('../utils/audio/non.mp3')
                    threadMp3.start()
                    time.sleep(0.5)
                    
                if tab[1] < -0.9 :
                    cherry.robot.rest_tilted_behave.start()
                    time.sleep(0.8)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase9.mp3')
                    threadMp3.start()

                    time.sleep(2.3)
                    cherry.robot.question_behave.start()
                    time.sleep(2)
                    cherry.robot.me_behave.start()
                    time.sleep(1.2)
                    cherry.robot.rest_position.start()
                    time.sleep(3)
                    cherry.robot.little_hug_behave.start()
                    time.sleep(1.5)
                    cherry.robot.question_behave.start()
                    time.sleep(2)
                    cherry.robot.rest_position.start()
                
                    
                if tab[0] < -0.9 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase11.mp3')
                    threadMp3.start()

                    cherry.robot.question_behave.start()
                    time.sleep(0.8)
                    cherry.robot.rest_position.start()
                    
                if tab[1] > 0.9 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase10.mp3')
                    threadMp3.start()
                    time.sleep(1)
                    cherry.robot.left_arms_behave.start()

                    time.sleep(1.5)
                    cherry.robot.right_arms_behave.start()

                    time.sleep(1.5)
                    cherry.robot.rest_position.start()

                    time.sleep(3.5)
                    cherry.robot.left_arm_up_behave.start()

                    time.sleep(1.5)
                    cherry.robot.rest_position.start()
                    
                if tab[2] < -0.9 and tab[0] > 0.9 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase12non.mp3')
                    threadMp3.start()
                    cherry.robot.sigh_behave.start()

                    time.sleep(1.4)
                    cherry.robot.rest_tilted_behave.start()
                
                elif tab[0] > 0.9 :
                    cherry.robot.little_hug_behave.start()
                    time.sleep(0.5)

                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase12.mp3')
                    threadMp3.start()

                    time.sleep(0.8)
                    cherry.robot.rest_position.start()
                
                if tab[3] <-0.9 :
                    threadMp3 = MP3Read('../utils/audio/agreable/Phrase13.mp3')
                    threadMp3.start()

                    time.sleep(3.5)
                    cherry.robot.question_behave.start()
                    time.sleep(2)
                    cherry.robot.show_front_hunkers_behave.start()

                    time.sleep(2.5)
                    cherry.robot.show_right_rest_behave.start()

                    time.sleep(2.2)
                    cherry.robot.rest_position.start()
                
                if tab[2] > 0.9 :
                    threadMp3 = MP3Read('../utils/audio/neSaisPas.mp3')
                    threadMp3.start()

                    time.sleep(1)
                    
                time.sleep(0.02)
                
    def stop(self):
        self.running = False

Lancement du controle gamepad


In [ ]:
pygame.init()
j = pygame.joystick.Joystick(0)
j.init()
print 'Initialized Joystick : %s' % j.get_name()
for m in cherry.robot.arms :
    m.compliant = False
for m in cherry.robot.motors:
    m.moving_speed = 0

thread = GamePadRead("Test")
thread.start()

In [ ]:
thread.stop()

Primitives


In [ ]:
#REPOS
cherry.robot.rest_position.start()

In [ ]:
#SE PENCHE SUR LE COTE
cherry.robot.rest_tilted_behave.start()

In [ ]:
#BRAS EN AVANT (QUESTION)
cherry.robot.question_behave.start()

In [ ]:
#BRAS GAUCHE EN L'AIR
cherry.robot.left_arm_up_behave.start()

In [ ]:
#SE MONTRE DE LA MAIN
cherry.robot.me_behave.start()

In [ ]:
#DESIGNE L'INTERLOCUTEUR PUIS LUI-MEME
cherry.robot.you_and_me_behave.start()

In [ ]:
#RIGOLE EN SE PENCHANT EN AVANT
cherry.robot.little_laugh_behave.start()

In [ ]:
#SOUPIRE EN ALLANT EN ARRIERE LEGEREMENT
cherry.robot.sigh_behave.start()

In [ ]:
#BRAS VERS LA GAUCHE
cherry.robot.left_arms_behave.start()

In [ ]:
#BRAS VERS LA DROITE
cherry.robot.right_arms_behave.start()

In [ ]:
#BRAS EN AVANT AVEC COUDES RENTRES POUR PETIT CALIN
cherry.robot.little_hug_behave.start()

In [ ]:
#POINTE DE LA MAIN
cherry.robot.show_front_hunkers_behave.start()

In [ ]:
#BRAS DROIT TENDU SUR LE COTE UN PEU VERS LE BAS
cherry.robot.show_right_rest_behave.start()